// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("38 PV1",38)]
  	    [HL7Field(HL7Version.v27, 38, HL7Repeat.False, HL7Required.True,"PV1")]
	    public PV1 PV1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("39 PRT",39)]
  	    [HL7Field(HL7Version.v27, 39, HL7Repeat.True, HL7Required.False,"PRT")]
  	    [HL7Field(HL7Version.v27, 45, HL7Repeat.True, HL7Required.False,"PRT")]
	    public PRT[] PRT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("40 PATIENT_VISIT_OBSERVATION",40)]
  	    [HL7Field(HL7Version.v27, 40, HL7Repeat.True, HL7Required.False,"PATIENT_VISIT_OBSERVATION_OSM_R26")]
	    public PATIENT_VISIT_OBSERVATION_OSM_R26[] PATIENT_VISIT_OBSERVATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("44 PID",44)]
  	    [HL7Field(HL7Version.v27, 44, HL7Repeat.False, HL7Required.False,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("46 NK1",46)]
  	    [HL7Field(HL7Version.v27, 46, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PV1 = PopSegmentParseAndCheckRequired<PV1>(availableData, options, "PV1");
			PRT = PopSegmentParseAndCheckRequiredArray<PRT>(availableData, options, "PRT");
			PATIENT_VISIT_OBSERVATION = ProcessGroupArray<PATIENT_VISIT_OBSERVATION_OSM_R26>(availableData, options, "PATIENT_VISIT_OBSERVATION");
			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPV1 = availableData.StartsWith("PV1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PV1", options.Version) || isPV1) {
				return isPV1;
			}
			bool isPRT = availableData.StartsWith("PRT", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRT", options.Version) || isPRT) {
				return isPRT;
			}
			PATIENT_VISIT_OBSERVATION_OSM_R26 testPATIENT_VISIT_OBSERVATION_OSM_R26 = new PATIENT_VISIT_OBSERVATION_OSM_R26();
			bool grpCCPATIENT_VISIT_OBSERVATION_OSM_R26 = (testPATIENT_VISIT_OBSERVATION_OSM_R26.CanConsume(availableData, options));
			if (IsRequired("PATIENT_VISIT_OBSERVATION", options.Version) || grpCCPATIENT_VISIT_OBSERVATION_OSM_R26) {
				return grpCCPATIENT_VISIT_OBSERVATION_OSM_R26;
			}
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			bool isNK1 = availableData.StartsWith("NK1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NK1", options.Version) || isNK1) {
				return isNK1;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "SUBJECT_POPULATION_LOCATION_IDENTIFICATION";
			}
        }

        static SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PV1 != null) {
			string segmentValue = PV1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PRT != null && PRT.Length > 0) {
			for (int i = 0; i < PRT.Length; i++) {
				string segmentValue = PRT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PATIENT_VISIT_OBSERVATION != null && PATIENT_VISIT_OBSERVATION.Length > 0) {
			for (int i = 0; i < PATIENT_VISIT_OBSERVATION.Length; i++) {
				string segmentValue = PATIENT_VISIT_OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NK1 != null && NK1.Length > 0) {
			for (int i = 0; i < NK1.Length; i++) {
				string segmentValue = NK1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

